package com.gmlive.common.ui.app;

import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.gmlive.common.ui.app.annotation.Immerse;
import com.gmlive.common.ui.systembartint.SystemBarUtil;

/**
 * baseActivity，支持全屏设置、标题设置
 * @作者: 姜志敏
 * @日期: 2019-11-20
 */
public class IkCompatActivity extends AppCompatActivity {
    private Immerse immerse;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setupImmerse();
    }

    @Override
    public void setContentView(int layoutResID) {
        super.setContentView(layoutResID);

        setFitSystemWindows();
    }

    @Override
    public void setContentView(View view) {
        super.setContentView(view);

        setFitSystemWindows();
    }

    @Override
    public void setContentView(View view, ViewGroup.LayoutParams params) {
        super.setContentView(view, params);

        setFitSystemWindows();
    }

    private void setupImmerse() {
        immerse = getClass().getAnnotation(Immerse.class);
        if (immerse != null) {
            if (immerse.translucentSystemBars()) {
                SystemBarUtil.setTranslucentSystemBars(this);
            } else if (immerse.translucentStatus()) {
                SystemBarUtil.setTranslucentStatus(this);
            }

            // 状态栏颜色
            SystemBarUtil.setStatusBarDarkTheme(this, immerse.darkStatusBar());
        }
    }

    private void setFitSystemWindows() {
        if (immerse != null) {
            SystemBarUtil.setRootViewFitsSystemWindows(this, immerse.fitSystemWindows());
        }
    }
}
